//
//  AnswerModel.swift
//  甜言蜜语
//
//  Created by 王剑伟 on 16/6/20.
//  Copyright © 2016年 wl. All rights reserved.
//

import Foundation
import SwiftyJSON

class AnswerCommentModel : NewsModelInitProtocol {
    var id: String
    var message: String
    
    required init(json: JSON) {
        id = json["id"].stringValue
        message = json["message"].stringValue
    }
}

class AnswerReplyComment: NewsModelInitProtocol {
    var name: String
    var message: String
    
    required init(json: JSON) {
        name = json["name"].stringValue
        message = json["message"].stringValue
    }
}

class AnswerModel : NSObject, NSCoding, NewsModelInitProtocol {
    var id: String
    var docid: String
    var name: String
    var userAddress: String
    var message: String
    var suppose: String
    var timg: String
    var floor: Int
    var commentid: Int
    var commenttime: String
    var childnum: Int
    var user: Int
    var isdianzan: Bool
    var reply: Int?
    var comment: AnswerCommentModel?
    var replyComment: AnswerReplyComment?
    
    required init(json: JSON) {
        id = json["id"].stringValue
        docid = json["docid"].stringValue
        name = json["name"].stringValue
        userAddress = json["userAddress"].stringValue
        suppose = json["suppose"].stringValue
        message = json["message"].stringValue
        timg = json["timg"].stringValue
        floor = json["floor"].intValue
        commentid = json["commentid"].intValue
        commenttime = json["commenttime"].stringValue
        childnum = json["childnum"].intValue
        user = json["user"].intValue
        isdianzan = json["isdianzan"].boolValue
        reply = json["reply"].intValue
        comment = AnswerCommentModel(json: json["comment"])
        replyComment = AnswerReplyComment(json: json["replyComment"])
    }
    
    required init?(coder decoder: NSCoder) {
        id = decoder.decodeObjectForKey("id") as! String
        docid = decoder.decodeObjectForKey("docid") as! String
        name = decoder.decodeObjectForKey("name") as! String
        userAddress = decoder.decodeObjectForKey("userAddress") as! String
        suppose = decoder.decodeObjectForKey("suppose") as! String
        message = decoder.decodeObjectForKey("message") as! String
        timg = decoder.decodeObjectForKey("timg") as! String
        floor = decoder.decodeObjectForKey("floor") as! Int
        commentid = decoder.decodeObjectForKey("commentid") as! Int
        commenttime = decoder.decodeObjectForKey("commenttime") as! String
        childnum = decoder.decodeObjectForKey("childnum") as! Int
        user = decoder.decodeObjectForKey("user") as! Int
        isdianzan = decoder.decodeObjectForKey("isdianzan") as! Bool
        reply = decoder.decodeObjectForKey("reply") as? Int
        comment = decoder.decodeObjectForKey("comment") as? AnswerCommentModel
        replyComment = decoder.decodeObjectForKey("replyComment") as? AnswerReplyComment
    }
    
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(id, forKey: "id")
        aCoder.encodeObject(docid, forKey: "docid")
        aCoder.encodeObject(name, forKey: "name")
        aCoder.encodeObject(userAddress, forKey: "userAddress")
        aCoder.encodeObject(suppose, forKey: "suppose")
        aCoder.encodeObject(message, forKey: "message")
        aCoder.encodeObject(timg, forKey: "timg")
        aCoder.encodeObject(floor, forKey: "floor")
        aCoder.encodeObject(commentid, forKey: "commentid")
        aCoder.encodeObject(commenttime, forKey: "commenttime")
        aCoder.encodeObject(childnum, forKey: "childnum")
        aCoder.encodeObject(user, forKey: "user")
        aCoder.encodeObject(isdianzan, forKey: "isdianzan")
        aCoder.encodeObject(reply, forKey: "reply")
        aCoder.encodeObject(comment, forKey: "comment")
        aCoder.encodeObject(replyComment, forKey: "replyComment")
    }
}